package com.hcq.service;

import com.common.base.BaseService;
import com.common.entity.Hotelroomitem;
import com.common.entity.PageParam;
import com.common.entity.Proposal;
import com.common.entity.Rsp;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hcq.mapper.ProposalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.UUID;

@Service
public class ProposalService implements BaseService<Proposal> {

    @Autowired
    ProposalMapper proposalMapper;


    @Override
    public PageInfo<Proposal> searchSomeByPage(PageParam<Proposal> pageParam) {
        if(!StringUtils.isEmpty(pageParam.getSuperSearchKeyWord())){
            //执行高级检索
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Proposal> newscategoryList=proposalMapper.superSearch(pageParam.getSuperSearchKeyWord());
            PageInfo<Proposal> newshotelPageInfo = new PageInfo<Proposal>(newscategoryList);

            return newshotelPageInfo;

        }else{
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Proposal> newscategoryList=proposalMapper.searchSomeByPage(pageParam.getModel());
            PageInfo<Proposal> newshotelPageInfo = new PageInfo<Proposal>(newscategoryList);

            return newshotelPageInfo;

        }
    }

    @Override
    public Proposal getOneById(String id) {
        return null;
    }

    @Override
    public Rsp addOne(Proposal proposal) {
        proposal.setId(UUID.randomUUID().toString().replace("-",""));
        return proposalMapper.addOne(proposal)==1?Rsp.success("添加成功"):Rsp.fail().msg("添加失败");
    }

    @Override
    public Rsp update(Proposal proposal) {
        return proposalMapper.update(proposal)==1?Rsp.success("修改成功"):Rsp.fail().msg("修改失败");
    }

    @Override
    public Rsp deleteLogical(Proposal proposal) {
        proposal.setDeleted(1);
        return proposalMapper.update(proposal)==1?Rsp.success("逻辑删除成功"):Rsp.fail().msg("逻辑删除失败");
    }
}
